<?php

namespace app\api\controller;

use app\common\controller\Api;
use think\Db;
use think\Validate;
use \app\common\model\Studylevel as StudylevelModel;
use \app\common\model\SchoolStudyLevelRelation;

/**
 * 学段接口
 */
class Studylevel extends Api
{

    /**
     * 学段列表
     * @var array
     */
    protected $noNeedRight = '*';

    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new StudylevelModel();
        $this->schoolStudyLevelRelationModel = new SchoolStudyLevelRelation();
    }
    /**
     * 查询学段表
     * @ApiTitle    (查询学段表)
     * @ApiMethod  (GET)
     * @ApiParams  (name="school_id", type="number", required=true, description="学校ID")
     * @ApiReturnParams   (name="code", type="integer", required=true, sample="0")
     * @ApiReturnParams   (name="msg", type="string", required=true, sample="查询成功")
     * @ApiReturn   ({
        'code':'200',
        'msg':'查询成功',
        'time': "",
        'data': $row
     })
     */
    public function levelIndex()
    {

        $data = input('get.');
        $schoolId = $data['school_id'];
        if (!$schoolId || !Validate::is($schoolId, 'number')) {
            $this->error('参数错误');
        }

        $dis = [
            'school_id' => $schoolId,
        ];
        $studyLevel =$this->schoolStudyLevelRelationModel->dataList($dis);
        $studyLevelId = array_column($studyLevel, 'study_level_id');
        
        $dis = [
            'id' => ['in' ,$studyLevelId],
        ];
        $row = $this->model->dataList($dis);
        
        $this->success('查询成功', $row);
    }
}